{% extends myBundleName ~ ':Layout:layout.html.twig' %}

{% block title %}{{ myTitlePrefix }} Schedule {% endblock %}

{% block content %}
{% include 'ZaysoCoreBundle:Schedule:Search/referee.html.twig' %}
<div class="schedule-list">
    <table border="1" style="max-width: 850px;">
        <tr><th colspan="7">Referee Schedule 2012 - Game Count {{ gameCount }}</th></tr>
        <tr>
            <td>Game</td>
            <td>DOW Time</td>
            <td>Field</td>
            <td>Pool</td>
            <td>Home / Away Teams</td>
            <td>Official Signup</td>
        </tr>
        {% for game in games %}
        <tr id="ref-sched-{{game.num}}" class="game-status-{{game.status}}">
            <td>
                {% if 0 %}
                <a href="{{ path('zayso_core_schedule_game_edit', { 'id': game.id })}}">{{ game.getNum() }}</a>
                {% else %}
                {{ game.num }}
                {% endif %}
            </td>
            <td>{{ game_date(game.date) }} {{ game_time(game.time) }}</td>
            <td>{{ game.fieldDesc      }}</td>
            <td>{{ game.pool           }}</td>
            <td>
                {% for teamRel in game.teams %}
                    {% set itemClass = game_team_class(teamIds,teamRel.team) %}
                    {% if  itemClass %}
                        <span class="{{ itemClass }}">{{ teamRel.team.desc }}</span><br />
                    {% else %}
                        {{ teamRel.team.desc }}<br />
                    {% endif %}
                {% endfor %}
            </td>
            <td><table class="game-officials-list">
                {% for gamePerson in game.eventPersonsSorted  %}
                {% set person = gamePerson.personz %}
                <tr>
                    <td>
                        {% if is_granted('ROLE_USER') and (game.isPoolPlay or game.isSoccerfest or 1) %}
                        <a href="{{ path('zayso_core_schedule_referee_assign', { 'id': game.id, 'pos': gamePerson.type }) }}">
                           {{ gamePerson.type }}:</a>
                        {% else %}
                           {{ gamePerson.type }}:
                        {% endif %}
                    </td>
                    <td>
                    {% set itemClass = game_person_class(personIds,person) %}
                    {% if  itemClass %}
                        <span class="{{ itemClass }}">{{ person.personName }}</span>
                    {% else %}
                        {{ person.personName }}
                    {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </table></td>
        </tr>
        {% endfor %}       
    </table>
</div>
<style>
.team-hilite   { color: green; }
.person-hilite { color: green; }
</style>

{% endblock %}

{% block stylesheets %}
    {{ parent() }}
    {% include 'ZaysoCoreBundle:Layout:jquery-ui-css.html.twig' %}
{% endblock %}
{% block javascripts %}
    {{ parent() }}
    {% include 'ZaysoCoreBundle:Layout:jquery-ui-js.html.twig' %}

<script>

$(document).ready(function() 
{
    // Check loading
    // Zayso.exclaim('Referee Schedule');
   
    // do stuff when DOM is ready
    $('.zayso-checkbox-all').change(Zayso.checkboxAll);
    
    $('.zayso-date-gen').change(Zayso.dateGen);
    
    $('.zayso-date-desc').datepicker({
        dateFormat: 'D M dd yy',
        firstDay: 0,
        
        numberOfMonths:   3,
        showCurrentAtPos: 1, // Confusing for Dec/Jan, fixed in beforeShow
        
        showOtherMonths: true,
        selectOtherMonths: true,
        
        changeMonth: true,
        changeYear:  true,
        yearRange: '2001:2016', // Reversing does not seem to work
        
        beforeShow: function(input, inst) 
        { 
            var options = { showCurrentAtPos: 1 };
            
            var date = $(input).val();
            var month = date.substring(4,7);
 
            if (month == 'Jan') options.showCurrentAtPos = 0;
            if (month == 'Aug') options.showCurrentAtPos = 0;
            
          //console.log(month + ' ' +  options.showCurrentAtPos);
             
            return options;
            
            alert('Before Show ' + $(input).val());
        },
        
        // onChange would be nice but would need anothe hidden value
        onClosex: Zayso.dateChanged,
        
        onClose: function (dateText, inst)
        {
            // Convert date to standard format
            // Can't call static methods dynamically
            var dateFormat = $(this).datepicker('option','dateFormat');
            var date = $.datepicker.parseDate (dateFormat,dateText);
            dateText = $.datepicker.formatDate('yymmdd',date);
            
            // Sets the scope to the dom element
            Zayso.dateChanged.call(this,dateText);
            return;
            
            alert('Date: ' + dateText);
            return;
            var name = $(this).attr('name');
          //var name =    $(this).html();
            alert('Selected ' + name + ' ' + $(this).val());
        }
    });
   
});
</script>

{% endblock %}
